using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Web.Shop.Member;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_MBF_UserCardRecode : Member, IRequiresSessionState
{
	protected DropDownList DropType;
	protected TextBox txtCardNumber;
	protected TextBox begindate;
	protected TextBox EndDate;
	protected Button sb;
	protected GridView GridView1;
	private UserCardStore bllCardStore = UserCardStore.instance;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
		if (!base.IsPostBack)
		{
			string selectValue = Fetch.Get("CardType");
			string text = Fetch.Get("CardNumber");
			this.DropType.ddlSelect(selectValue);
			this.txtCardNumber.Text = text;
			this.BindGridView();
		}
		this.begindate.Attributes.Add("onclick", "SelectDate(" + this.begindate.UniqueID + ",'yyyy-MM-dd');");
		this.EndDate.Attributes.Add("onclick", "SelectDate(" + this.EndDate.UniqueID + ",'yyyy-MM-dd');");
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindGridView();
	}
	protected void BindGridView()
	{
		string text = this.GetQuestString();
		if (text == "")
		{
			text = "1=2";
		}
		this.GridView1.DataSource = Blls.bllUserCardRecord.GetListRowid(2147483647, text, "Rowid asc", new string[0]).Tables[0];
		this.GridView1.DataBind();
	}
	protected string GetQuestString()
	{
		string text = " PurchaseUserID=" + base.user.UserID + " ";
		string selectValue = this.DropType.GetSelectValue(new string[0]);
		string result;
		if (selectValue != "")
		{
			if (selectValue == "-1")
			{
				text = "UserID=" + base.user.UserID;
			}
			else
			{
				if (selectValue == "-2")
				{
					text = "UserID=" + base.user.UserID;
				}
				else
				{
					if (selectValue == "-3")
					{
						text = "1=1 ";
					}
					else
					{
						text = "1=1 ";
					}
				}
			}
			text += string.Format(" and CardType='{0}' ", selectValue);
			string text2 = this.txtCardNumber.Text.Trim();
			if (text2 != "")
			{
				text += string.Format(" and CardNumber='{0}' ", text2);
			}
			string text3 = this.begindate.Text;
			if (text3 != string.Empty)
			{
				try
				{
					Convert.ToDateTime(text3);
				}
				catch
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
				}
				text = text + "and datediff(dd,UserTime,'" + text3 + "')<=0 ";
			}
			string text4 = this.EndDate.Text;
			if (text4 != string.Empty)
			{
				try
				{
					Convert.ToDateTime(text4);
				}
				catch
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
				}
				if (!string.IsNullOrEmpty(text3) && Convert.ToDateTime(text4) < Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
				text = text + "and datediff(dd,UserTime,'" + text4 + "')>=0 ";
			}
			result = text;
		}
		else
		{
			MessageBox.Show(this, "请选择卡类型！");
			result = "";
		}
		return result;
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.BindGridView();
	}
	protected string GetUserNameByid(object obj)
	{
		string userNameByid = StaticFun.GetUserNameByid(new int?(obj.ToString().ToInt32(new int[0])));
		return (userNameByid == "") ? "未知" : userNameByid;
	}
	protected string GetData(object obj)
	{
		return Convert.ToDateTime(obj).ToShortDateString();
	}
	protected string GetCardType(object obj)
	{
		string text = obj.IsNull(new object[0]);
		string text2 = text;
		string result;
		if (text2 != null)
		{
			if (text2 == "-1")
			{
				result = "VIP卡";
				return result;
			}
			if (text2 == "-2")
			{
				result = "礼品卡";
				return result;
			}
			if (text2 == "-3")
			{
				result = "中奖券";
				return result;
			}
		}
		result = "未知卡";
		return result;
	}
}
